

package com.yyk.yykywd.ui.customer;

import butterknife.BindView;


import android.os.Bundle;
import androidx.fragment.app.Fragment;

import android.view.View;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.yyk.yykywd.R;
import com.yyk.yykywd.adapter.CommonTabPagerAdapter;
import com.yyk.yykywd.base.BaseFragment;
import com.yyk.yykywd.widght.CustomViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.OnClick;


/**
 * 客户 fragment
 */
public class CustomerFragment extends BaseFragment {
    public static final String TAG = "CustomerFragment";

    @BindView(R.id.tv_search)
    TextView tvSearch;

    @BindView(R.id.xblyout)
    XTabLayout xblyout;
    @BindView(R.id.vp)
    CustomViewPager vp;
    private String type = "0";
    private CommonTabPagerAdapter tablyoutAdapter;

    public CustomerFragment() {
        // Required empty public constructor
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_customer_test;
    }

    @Override
    public void initView() {
        initTablyout(true);
    }


    @Override
    public void initData() {


    }

    /**
     * 初始化tablyout
     */
    private void initTablyout(boolean flag) {
        String[] title = {"全部", "未拜访", "跟进中", "合作达成", "合作暂未达成"};
        String[] state = {"0", "1", "2", "3", "4"};
        List<String> nameString = new ArrayList<>();
        final List<String> idInteger = new ArrayList<>();
        for (int i = 0; i < title.length; i++) {
            nameString.add(title[i]);
            idInteger.add(state[i]);
        }
        tablyoutAdapter = new CommonTabPagerAdapter(getChildFragmentManager()
                , nameString.size(), nameString, getActivity());
        tablyoutAdapter.setListener(new CommonTabPagerAdapter.TabPagerListener() {
            @Override
            public Fragment getFragment(int position) {


                CustomerList2Fragment fragment = CustomerList2Fragment.newInstance(position);
                Bundle bundle = new Bundle();
                bundle.putString(CustomerList2Fragment.ARGS_PAGE, idInteger.get(position));
                bundle.putString("type", type);
                fragment.setArguments(bundle);
                return fragment;
            }
        });
        vp.setPageTransformer(true, new NoSlidingPageTransformer());
        vp.setAdapter(tablyoutAdapter);
        xblyout.setupWithViewPager(vp);
        vp.setCurrentItem(0);


    }


    /**
     * 4.搜索
     *
     * @param view
     */

    @OnClick({R.id.tv_search})
    public void onViewClicked(View view) {

        switch (view.getId()) {

            case R.id.tv_search:
//                Intent intent = new Intent(getActivity(), CustomerSearchActivity.class);
//                startActivityForResult(intent, REQUEST_CODE);
                startAct(CustomerSearchActivity.class);
                break;
        }
    }


}
